package cn.iocoder.yudao.module.biz.service.emergencyReservePlainP;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainP.vo.BizEmergencyReservePlainPCreateReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainP.vo.BizEmergencyReservePlainPExportReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainP.vo.BizEmergencyReservePlainPPageReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainP.vo.BizEmergencyReservePlainPUpdateReqVO;
import cn.iocoder.yudao.module.biz.convert.emergencyReservePlainP.BizEmergencyReservePlainPConvert;
import cn.iocoder.yudao.module.biz.dal.dataobject.emergencyReservePlainP.BizEmergencyReservePlainPDO;
import cn.iocoder.yudao.module.biz.dal.mysql.emergencyReservePlainP.BizEmergencyReservePlainPMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.biz.enums.ErrorCodeConstants.EMERGENCY_RESERVE_PLAIN_P_NOT_EXISTS;

/**
 * 应急人员 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class BizEmergencyReservePlainPServiceImpl implements BizEmergencyReservePlainPService {

    @Resource
    private BizEmergencyReservePlainPMapper emergencyReservePlainPMapper;

    @Override
    public String createEmergencyReservePlainP(BizEmergencyReservePlainPCreateReqVO createReqVO) {
        // 插入
        BizEmergencyReservePlainPDO emergencyReservePlainP = BizEmergencyReservePlainPConvert.INSTANCE.convert(createReqVO);
        emergencyReservePlainPMapper.insert(emergencyReservePlainP);
        // 返回
        return emergencyReservePlainP.getId();
    }

    @Override
    public void updateEmergencyReservePlainP(BizEmergencyReservePlainPUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateEmergencyReservePlainPExists(updateReqVO.getId());
        // 更新
        BizEmergencyReservePlainPDO updateObj = BizEmergencyReservePlainPConvert.INSTANCE.convert(updateReqVO);
        emergencyReservePlainPMapper.updateById(updateObj);
    }

    @Override
    public void deleteEmergencyReservePlainP(String id) {
        // 校验存在
        this.validateEmergencyReservePlainPExists(id);
        // 删除
        emergencyReservePlainPMapper.deleteById(id);
    }

    private void validateEmergencyReservePlainPExists(String id) {
        if (emergencyReservePlainPMapper.selectById(id) == null) {
            throw exception(EMERGENCY_RESERVE_PLAIN_P_NOT_EXISTS);
        }
    }

    @Override
    public BizEmergencyReservePlainPDO getEmergencyReservePlainP(String id) {
        return emergencyReservePlainPMapper.selectById(id);
    }

    @Override
    public List<BizEmergencyReservePlainPDO> getEmergencyReservePlainPList(Collection<String> ids) {
        return emergencyReservePlainPMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<BizEmergencyReservePlainPDO> getEmergencyReservePlainPPage(BizEmergencyReservePlainPPageReqVO pageReqVO) {
        return emergencyReservePlainPMapper.selectPage(pageReqVO);
    }

    @Override
    public List<BizEmergencyReservePlainPDO> getEmergencyReservePlainPList(BizEmergencyReservePlainPExportReqVO exportReqVO) {
        return emergencyReservePlainPMapper.selectList(exportReqVO);
    }

    @Override
    public List<BizEmergencyReservePlainPDO> getAll() {
        return emergencyReservePlainPMapper.selectList();
    }

}
